﻿@model IEnumerable<LunchCommand.Models.User>

@{
    ViewBag.Title = "Luncher Leaderboards";
}

<h2>Luncher Leaderboards</h2>

<table class="table">
    <tr>
        <th>
            Total Lunches Eaten
        </th>
        <th>
            Name
        </th>
        <th>
            Preferred Venues
        </th>
        <th>
            Hated Venues
        </th>
        <th>
            Last Lunch
        </th>
        <th>
            Last Login
        </th>
    </tr>

    @foreach (var item in Model)
    {
        var lunches = item.LunchesEaten.Where(le=>le.LunchTime < DateTime.Now).OrderBy(le => le.LunchTime).Select(le => le.LunchTime).ToArray();

        <tr>
            <td>
                @lunches.Count()
            </td>
            <td>
                @item.Name <span class="text-muted">(@item.WindowsUsername)</span>
            </td>
            <td>
                <a href="#" title="@String.Join("<br/>", item.VenuesPreferring.Select(v=>v.Name))"> @item.VenuesPreferring.Count()</a>
            </td>
            <td>
                <a href="#" title="@String.Join("<br/>", item.VenuesRefusing.Select(v=>v.Name))">@item.VenuesRefusing.Count()</a>
            </td>
            <td>
                @(lunches.Any()? lunches.Last().ToShortDateString() : "N/A")
            </td>
            <td>
                @item.LastActionTime.ToShortDateString()
            </td>
        </tr>
    }

</table>


@section scripts{
    @Styles.Render("~/Scripts/jquery-ui-tooltips/jquery-ui.css")
    @Scripts.Render("~/Scripts/jquery-ui-tooltips/jquery-ui.js")

    <script>
        $(function () {
            $("table").tooltip({
                show: {
                    effect: "slideDown",
                    delay: 250
                },
                content: function () {
                    return $(this).attr('title');
                }
            });
        })
    </script>
}
